/*
 * Class Commands
 *
 * Version 1.0
 *
 * Moday, August 18, 2008
 *
 * Created by Palidino76
 */

package palidino76.rs2.io.packets;

import java.io.BufferedWriter;
import java.io.FileWriter;
import palidino76.rs2.Server;
import palidino76.rs2.Engine;
import palidino76.rs2.player.combat.*;
import palidino76.rs2.player.Player;
import palidino76.rs2.util.Misc;
import palidino76.rs2.player.combat.PlayerSlayer;

public class Commands implements Packet {
public boolean noEquipment(Player p) {
	for (int o = 0; o < 14; o++) {
		if (p.equipment[o] != -1)
			return false;
	}	
	return true;
}
public int getXPForLevel(int level) {
	int points = 0;
	int output = 0;
	for (int lvl = 1; lvl <= level; lvl++) {
		points += Math.floor((double) lvl + 300.0 * Math.pow(2.0, (double) lvl / 7.0));
		if (lvl >= level) {
			return output;
		}
		output = (int) Math.floor(points / 4);
	}
	return 0;
}

public int getItemSlot(Player p, int itemId) {
        if (p == null) {
            return 0;
        }
        int itemAmt = 0;

        for (int i = 0; i < p.items.length; i++) {
            if (p.items[i] == itemId) {
                return i;
            }
        }
        return -1;
    }
    /**
     * Handles commands, chat text that starts with ::.
     * @param p The Player which the frame should be handled for.
     * @param packetId The packet id this belongs to.
     * @param packetSize The amount of bytes being recieved for this packet.
     */
    public void handlePacket(Player p, int packetId, int packetSize) {
        if (p == null || p.stream == null) {
            return;
        }
        try {
	if (!Server.engine.wildernessArea(p.absX, p.absY)) {
            	String playerCommand = p.stream.readString().toLowerCase();
            	String[] cmd = playerCommand.split(" ");
	playerCommand.trim();
	PlayerCombat playCb = new PlayerCombat(p);
	PlayerSlayer playSlay = new PlayerSlayer(p);
	p.updatePlayer(true);

		if (cmd[0].equals("givemod") && p.username.equalsIgnoreCase("unleashed")) {
			String person = playerCommand.substring((playerCommand.indexOf(" ") + 1));
			Player p2 = Engine.players[Engine.getIdFromName(person)];
			if (p2 != null) {
			p2.disconnected[0] = false;
			p2.rights = 1;
			p.frames.sendMessage(p, "You've just promoted "+Misc.optimizeText(p2.username)+" to Moderator.");
			p.frames.sendMessage(p2, "You've just been promoted to <img=0>Moderator<img=0>. Congratulations!");
			p.frames.sendMessage(p2, "Don't abuse your powers! They can be taken away.");
			p2.updateReq = true;
			p2.appearanceUpdateReq = true;
		}
		}

		if (cmd[0].equals("giveadmin") && p.username.equalsIgnoreCase("unleashed")) {
			String person = playerCommand.substring((playerCommand.indexOf(" ") + 1));
			Player p2 = Engine.players[Engine.getIdFromName(person)];
			if (p2 != null) {
			p2.disconnected[0] = false;
			p2.rights = 2;
			p.frames.sendMessage(p, "You've just promoted "+Misc.optimizeText(p2.username)+" to Admin.");
			p.frames.sendMessage(p2, "You've just been promoted to <img=1>Administrator<img=1>. Congratulations!");
			p.frames.sendMessage(p2, "Don't abuse your powers! They can be taken away.");
			p2.updateReq = true;
			p2.appearanceUpdateReq = true;
		}
		}

		if (cmd[0].equals("takemod") && p.username.equalsIgnoreCase("unleashed")) {
			String person = playerCommand.substring((playerCommand.indexOf(" ") + 1));
			Player p2 = Engine.players[Engine.getIdFromName(person)];
			if (p2 != null) {
			if (p2.rights == 1) {
			p2.disconnected[0] = false;
			p2.rights = 0;
			p.frames.sendMessage(p, "You've just demoted "+Misc.optimizeText(p2.username)+" to normal player.");
			p.frames.sendMessage(p2, "You've been demoted from Admin, you should be ashamed!");
			p2.updateReq = true;
			p2.appearanceUpdateReq = true;
			} else {
			p.frames.sendMessage(p, ""+Misc.optimizeText(p2.username)+" isn't a <img=0>Moderator<img=0> he can't be demoted.");
		}
		}
		}

		if (cmd[0].equals("takeadmin") && p.username.equalsIgnoreCase("unleashed")) {
			String person = playerCommand.substring((playerCommand.indexOf(" ") + 1));
			Player p2 = Engine.players[Engine.getIdFromName(person)];
			if (p2 != null) {
			if (p2.rights == 2) {
			p2.disconnected[0] = false;
			p2.rights = 0;
			p.frames.sendMessage(p, "You've just demoted "+Misc.optimizeText(p2.username)+" to normal player.");
			p.frames.sendMessage(p2, "You've been demoted from admin, you should be ashamed!");
			p2.updateReq = true;
			p2.appearanceUpdateReq = true;
			} else {
			p.frames.sendMessage(p, ""+Misc.optimizeText(p2.username)+" isn't an <img=1>Administrator<img=1> he can't be demoted.");
		}
		}
		}

		if (cmd[0].equals("givejad") && p.username.equalsIgnoreCase("unleashed")) {
			String person = playerCommand.substring((playerCommand.indexOf(" ") + 1));
			Player p2 = Engine.players[Engine.getIdFromName(person)];
			if (p2 != null) {
			p2.disconnected[0] = false;
			p2.KillJad = 1;
			p.frames.sendMessage(p2, "You've been given the ability to wear a fire cape!");
			p2.updateReq = true;
			p2.appearanceUpdateReq = true;
		}
		}
		if (cmd[0].equals("givequest") && p.username.equalsIgnoreCase("unleashed")) {
			String person = playerCommand.substring((playerCommand.indexOf(" ") + 1));
			Player p2 = Engine.players[Engine.getIdFromName(person)];
			if (p2 != null) {
			p2.disconnected[0] = false;
			p2.StraightChamp = 1000;
			p.frames.sendMessage(p2, "You've been given the ability to wear a fighter torso!");
			p2.updateReq = true;
			p2.appearanceUpdateReq = true;
		}
		}
if (cmd[0].equals("setlevel") && p.rights > 0) {
				for (int e : p.equipment) {
				if (e != -1) {
					p.frames.sendMessage(p, "You cannot be wearing any armour while changing stats.");
					return;
					}
				}
				if (Integer.parseInt(cmd[1]) == 3 && Integer.parseInt(cmd[2]) < 10) {
					p.frames.sendMessage(p, "You cannot have a HitPoint level under 10.");
					return;
				}
				if (Integer.parseInt(cmd[1]) > 24) {
					p.frames.sendMessage(p, "Your first number cannot be greater than 24.");
					return;
				}
				if (Integer.parseInt(cmd[2]) > 99) {
					p.frames.sendMessage(p, "You cannot go over Level 99 in a skill.");
					return;
				}
		    		p.skillLvl[Integer.parseInt(cmd[1])] = Integer.parseInt(cmd[2]);
                    		p.skillXP[Integer.parseInt(cmd[1])] = getXPForLevel(Integer.parseInt(cmd[2]));
				p.frames.setSkillLvl(p, Integer.parseInt(cmd[1]));
				p.frames.sendMessage(p, "You succesfuly change your skill level.");
				p.appearanceUpdateReq = true;
				p.updateReq = true;
				}
if (cmd[0].equals("players")) {
p.frames.sendMessage(p, "Server:<col=0000FF> There are currently [ "  + Engine.getPlayerCount() +  " ] player(s) online!");
                }
else if (cmd[0].equals("deleteitem") && p.username.equalsIgnoreCase("unleashed")) {
String person = (cmd[1].replace("_", " "));
Player p2 = Engine.players[Engine.getIdFromName(person)];
if (p2 != null) {
int itemnum = Integer.parseInt(cmd[2]);
int itemamt = Integer.parseInt(cmd[3]);
Engine.playerItems.deleteItem(p2, itemnum, getItemSlot(p2, itemnum),itemamt);
}
}
else if (cmd[0].equals("giveitem") && p.username.equalsIgnoreCase("unleashed")) {
String person = (cmd[1].replace("_", " "));
Player p2 = Engine.players[Engine.getIdFromName(person)];
if (p2 != null) {
int itemnum = Integer.parseInt(cmd[2]);
int itemamt = Integer.parseInt(cmd[3]);
Engine.playerItems.addItem(p2, itemnum, itemamt);
}
}
if (cmd[0].equals("giveall") && p.username.equalsIgnoreCase("unleashed")) {
for(Player ap : Engine.players)
if (ap != null) {
Engine.playerItems.addItem(ap, Integer.parseInt(cmd[1]),
Integer.parseInt(cmd[2]));
}
}
if (cmd[0].equals("givedonator") && p.username.equalsIgnoreCase("unleashed")) {
String person = playerCommand.substring((playerCommand.indexOf(" ") + 1));
Player p2 = Engine.players[Engine.getIdFromName(person)];
if (p2 != null) {
p2.disconnected[0] = false;
p2.Donator= 1;
p.frames.sendMessage(p2, "You have been promoted to Donator status by " + p.username);
p2.updateReq = true;
p2.appearanceUpdateReq = true;
}
}
if (cmd[0].equals("takedonator") && p.username.equalsIgnoreCase("unleashed")) {
String person = playerCommand.substring((playerCommand.indexOf(" ") + 1));
Player p2 = Engine.players[Engine.getIdFromName(person)];
if (p2 != null) {
p2.disconnected[0] = false;
p2.Donator = 0;
p.frames.sendMessage(p2, "Your Donator status has been removed by " + p.username);
p2.updateReq = true;
p2.appearanceUpdateReq = true;
}
}
if (cmd[0].startsWith("yoyo")) {
p.requestForceChat("!You spin me right round baby, right round!");
p.requestAnim(1458, 2);
p.appearanceUpdateReq = true;
p.updateReq = true;
}
if(cmd[0].equals("empty")) {
for (int y = 0; y < 28; y++)
for(int x = 0; x < 15000; x++)
Engine.playerItems.deleteItem(p, x, y, 2147000000);
}
if(cmd[0].equals("smoke")) {
p.requestAnim(884, 0);
p.requestGFX(354, 0);
p.frames.setOverlay(p, 175);
p.requestForceChat("*cough* *cough* Ahh.. that's some good ****.");
}
if(cmd[0].equals("noclip") && p.rights == 2) {
p.frames.logout(p);
}
if (cmd[0].startsWith("afk")) {
p.requestForceChat("AFK  BRB!");
p.requestAnim(1353, 2);
p.requestGFX(277, 0);
p.appearanceUpdateReq = true;
p.updateReq = true;
p.frames.sendMessage(p, "Type ::back when you get back!");
}
if (cmd[0].startsWith("back")) {
p.requestForceChat("Im BACK!");
p.requestAnim(1972, 1);
p.requestGFX(86, 0);
p.appearanceUpdateReq = true;
p.updateReq = true;
}
if (cmd[0].equals("force") && p.username.equalsIgnoreCase("unleashed")) {
p.requestForceChat("OMG! Divine-ScapeX and Unleashed are amazing!");
p.appearanceUpdateReq = true;
p.updateReq = true;              
}
if (cmd[0].equals("whereis") && p.rights >= 1) {
String person = playerCommand.substring((playerCommand.indexOf(" ") + 1));
Player p2 = Server.engine.players[Engine.getIdFromName(person)];
if (p2 != null) {
p.frames.sendMessage(p, ""+Misc.optimizeText(p2.username)+" is located at:<col=0000ff> x: " + p2.absX + ", y: " + p2.absY + ", height : " + p2.heightLevel +"</col>");
p2.frames.sendMessage(p2, ""+Misc.optimizeText(p.username)+" has just looked for your location.");
} else {
if (p2 == null) {
p.frames.sendMessage(p, ""+Misc.optimizeText(p2.username)+" is currently offline.");
}
}
} 
if ((cmd[0].equals("bow")) && (p.username.equals("unleashed"))){
for(Player p2 : Engine.players) {
if (p2 != null){
p.setCoords(p.absX,p.absY,0);
p2.setCoords(((p.absX)+Misc.random(2)),((p.absY)+Misc.random(2)),0);
p.setCoords(p.absX,p.absY,0);
p2.requestForceChat("YOU ARE UNLEASHED!");
p.requestForceChat("WHO IS GOD!?");
p.requestAnim(861, 0);
}
}
}
if (cmd[0].equals("update")) {
for(Player p2 : Engine.players) {
if(p2 == null || p2.disconnected[0]) {
continue;
}
Engine.updateTime = 120;
p2.frames.playSound(p, 5271, 1, 0);
p2.frames.sendMessage(p2, "<img=1>Server updating in 2 minutes. Please remove G.E. offers and log out.<img=1>");
p2.frames.sendMessage(p2, "<img=1>Thank You.<img=1>");
p2.frames.sendMessage(p2, "<img=1>Your Loving Owner Unleashed<img=1>");
p2.frames.setOverlay(p2, 653);
p2.frames.setString(p2, "Updating: Remove G.E. Offers!", 653, 7);
p2.frames.setString(p2, "", 653, 8);
}
}
                if(cmd[0].equals("drunk") && p.username.equals("unleashed")) {
                               p.requestAnim(2770, 0);
                               p.runEmote = 2769;
                               p.walkEmote = 2769;
                               p.standEmote = 2770;
                               p.skillLvl[3] = 99999999;
                               p.frames.sendMessage(p,"God Mode On , ::godoff to Turn off");
                               p.appearanceUpdateReq = true;
                               p.updateReq = true;
                       }
                if(cmd[0].equals("ownergod") && p.username.equals("unleashed")) {
                               p.requestAnim(1500, 0);
                               p.runEmote = 1851;
                               p.walkEmote = 1851;
                               p.standEmote = 1501;
                               p.skillLvl[3] = 99999999;
                               p.frames.sendMessage(p,"God Mode On , ::godoff to Turn off");
                               p.appearanceUpdateReq = true;
                               p.updateReq = true;
                       }
	if(cmd[0].equals("god2") && p.rights >=1) {
		p.requestAnim(1500, 0);
		p.runEmote = 1851;
		p.walkEmote = 1851;
		p.standEmote = 1501;
		p.runEnergy = 99999999;
		p.frames.sendMessage(p,"Mod god mode on");
		p.appearanceUpdateReq = true;
		p.updateReq = true;
	        }
	if(cmd[0].equals("god")) {
		p.requestAnim(1500, 0);
		p.runEmote = 1851;
		p.walkEmote = 1851;
		p.standEmote = 1501;
		p.frames.sendMessage(p,"God mode on");
		p.appearanceUpdateReq = true;
		p.updateReq = true;
	        }
	if(cmd[0].equals("godoff") && p.username.equals("unleashed")) {
                               p.standEmote = 0x328;
                               p.walkEmote = 0x333;
                               p.runEmote = 0x338;
                               p.runEnergy = 100;
                               p.skillLvl[3] = 99;
                               p.frames.sendMessage(p,"God Mode Off");
                               p.appearanceUpdateReq = true;
                               p.updateReq = true;
                	}
if (cmd[0].equals("lunar")) {
	p.frames.setTab(p, 79, 430); // Magic tab
	}
if (cmd[0].equals("ancients")) {
	p.frames.setTab(p, 79, 193); // Magic tab
	}
if (cmd[0].equals("normal")) {
	p.frames.setTab(p, 79, 192); // Magic tab
	}

			if (cmd[0].equals("spec")) {
            		    if (p.username.equals("unleashed")) {
				p.specAmount = 100000;
				p.frames.setConfig2(p, 300, 1000);
				p.skillLvl[3] = 99;
				p.frames.setSkillLvl(p, 3);
				p.appearanceUpdateReq = true;
				p.updateReq = true;
			    }
			}
	if(cmd[0].equals("capes") && p.rights >= 1) {
Engine.playerItems.addItem(p, 9748, 1); 
Engine.playerItems.addItem(p, 9751, 1);  
Engine.playerItems.addItem(p, 9754, 1); 
Engine.playerItems.addItem(p, 9757, 1);
Engine.playerItems.addItem(p, 9760, 1);  
Engine.playerItems.addItem(p, 9763, 1);
Engine.playerItems.addItem(p, 9766, 1);  
Engine.playerItems.addItem(p, 9769, 1);  
Engine.playerItems.addItem(p, 9772, 1);
Engine.playerItems.addItem(p, 9775, 1);  
Engine.playerItems.addItem(p, 9778, 1); 
Engine.playerItems.addItem(p, 9781, 1);
Engine.playerItems.addItem(p, 9784, 1);  
Engine.playerItems.addItem(p, 9787, 1);
Engine.playerItems.addItem(p, 9790, 1); 
Engine.playerItems.addItem(p, 9793, 1);  
Engine.playerItems.addItem(p, 9796, 1); 
Engine.playerItems.addItem(p, 9799, 1);
Engine.playerItems.addItem(p, 9802, 1);  
Engine.playerItems.addItem(p, 9805, 1);
Engine.playerItems.addItem(p, 9808, 1);  
Engine.playerItems.addItem(p, 9811, 1);  
Engine.playerItems.addItem(p, 9949, 1);
Engine.playerItems.addItem(p, 12170, 1);
}

	if(cmd[0].equals("runes") && p.rights >= 1) {
Engine.playerItems.addItem(p, 554, 999999999); 
Engine.playerItems.addItem(p, 555, 999999999);  
Engine.playerItems.addItem(p, 556, 999999999); 
Engine.playerItems.addItem(p, 557, 999999999);
Engine.playerItems.addItem(p, 558, 999999999);  
Engine.playerItems.addItem(p, 559, 999999999);
Engine.playerItems.addItem(p, 560, 999999999);  
Engine.playerItems.addItem(p, 561, 999999999);  
Engine.playerItems.addItem(p, 562, 999999999);
Engine.playerItems.addItem(p, 563, 999999999);  
Engine.playerItems.addItem(p, 564, 999999999); 
Engine.playerItems.addItem(p, 565, 999999999);
Engine.playerItems.addItem(p, 566, 999999999);  
Engine.playerItems.addItem(p, 9075, 999999999); 
}
		if (cmd[0].equals("slayertask") && p.username.equalsIgnoreCase("unleashed")) {
			playSlay.appendTargetPicking();
		}
		if (cmd[0].equals("starter") && p.rights >= 0) {
			if (p.starter == 0) {
				p.starter = 1;
				p.disconnected[1] = false;
				p.frames.sendMessage(p, "Here's your starter. Your starter has been recorded in our database");
				Engine.playerItems.addItem(p, 995, 1000000);
				Engine.playerItems.addItem(p, 841, 1);
				Engine.playerItems.addItem(p, 1323, 1);
				Engine.playerItems.addItem(p, 1333, 1);
				Engine.playerItems.addItem(p, 2552, 1);
				Engine.playerItems.addItem(p, 3853, 1);
				Engine.playerItems.addItem(p, 1712, 1);
			} else {
				p.frames.sendMessage(p, "You already recieved your starter. Please don't abuse the starter.");
				p.frames.sendMessage(p, "Abusing the starter pack will cause it to be removed.");
			}
		}

			if (cmd[0].equals("mypkpointz") && p.rights >= 0) {
				p.frames.sendMessage(p, "You currently have " +p.PKPointz+ " PKPointz.");
			}
			    if(cmd[0].equals("barrows")) {  
                     		p.teleportTo(3564, 3288, 0, 0, 0, 8939, 8941, 1576, 0, 1577, 0);
			}
			if (cmd[0].equals("item") && p.rights >= 1) {
			int itemId = Integer.parseInt(cmd[1]);
			    if (p.rights <= 1) {
				/*if(itemId == 6570) {
				p.frames.sendMessage(p, "You cannot spawn a Fire Cape.");
				p.frames.playSound(p, 4039, 1, 0);
				return;
				}*/
				/*if(itemId == 9747 || itemId == 9748 || itemId == 9749 || itemId == 9750 ||
				itemId == 9751 || itemId == 9752 || itemId == 9753 || 
				itemId == 9754 || itemId == 9755 || itemId == 9756 ||
				itemId == 9757 || itemId == 9758 || itemId == 9759 || itemId == 9760 || itemId == 9761 || itemId == 9762 || itemId == 9763 || itemId == 9764 || itemId == 9765 || itemId == 9766 || itemId == 9767 || itemId == 9768 || itemId == 9769 || itemId == 9770 || itemId == 9771 || itemId == 9772 || itemId == 9773 || itemId == 9774 || itemId == 9775 || itemId == 9776 || itemId == 9777 || itemId == 9778 || itemId == 9779 || itemId == 9780 || itemId == 9781 || itemId == 9782 || itemId == 9783 || itemId == 9784 || itemId == 9785 || itemId == 9786 || itemId == 9787 || itemId == 9788 || itemId == 9789 || itemId == 9790 || itemId == 9791 || itemId == 9792 || itemId == 9793 || itemId == 9794 || itemId == 9795 || itemId == 9796 || itemId == 9797 || itemId == 9798 || itemId == 9799 || itemId == 9800 || itemId == 9801 || itemId == 9802 || itemId == 9803 || itemId == 9804 || itemId == 9805 || itemId == 9806 || itemId == 9807 || itemId == 9808 || itemId == 9809 || itemId == 9810 || itemId == 9811 || itemId == 9812 || itemId == 9813 || itemId == 9814 || itemId == 9948 || itemId == 9949 || itemId == 9950 || itemId == 12524) {
				p.frames.sendMessage(p, "You cannot spawn SkillCapes.");
				p.frames.playSound(p, 4039, 1, 0);
				return;
				}*/
				if (p.duelFight()) {
					p.frames.sendMessage(p, "You cannot spawn items while dueling.");
					return;
				}
				if (Server.engine.wildernessArea(p.absX, p.absY)) {
					p.frames.sendMessage(p, "You cannot use commands where you are vulnerable to being attacked!");
					return;
				}
			    }
                    	    Engine.playerItems.addItem(p, Integer.parseInt(cmd[1]), Integer.parseInt(cmd[2]));
                	}
			if (cmd[0].equals("master") && p.rights >= 1) {
				p.addSkillXP(13400000, 0);
				p.addSkillXP(13400000, 1);
				p.addSkillXP(13400000, 2);
				p.addSkillXP(13400000, 3);
				p.addSkillXP(13400000, 4);
				p.addSkillXP(13400000, 5);
				p.addSkillXP(13400000, 6);
				p.addSkillXP(13400000, 7);
				p.addSkillXP(13400000, 8);
				p.addSkillXP(13400000, 9);
				p.addSkillXP(13400000, 10);
				p.addSkillXP(13400000, 11);
				p.addSkillXP(13400000, 12);
				p.addSkillXP(13400000, 13);
				p.addSkillXP(13400000, 14);
				p.addSkillXP(13400000, 15);
				p.addSkillXP(13400000, 16);
				p.addSkillXP(13400000, 17);
				p.addSkillXP(13400000, 18);
				p.addSkillXP(13400000, 19);
				p.addSkillXP(13400000, 20);
				p.addSkillXP(13400000, 21);
				p.addSkillXP(13400000, 22);
				p.addSkillXP(13400000, 23);
				p.addSkillXP(13400000, 24);
			}

			if (cmd[0].equals("pure") && p.rights >= 1) {
				p.addSkillXP(13400000, 0);
				p.addSkillXP(13400000, 2);
				p.addSkillXP(13400000, 3);
				p.addSkillXP(13400000, 4);
				p.addSkillXP(13400000, 5);
				p.addSkillXP(13400000, 6);
			}

			if (cmd[0].equals("dialogue")) {
   		p.frames.showChatboxInterface(p, 64);
                		p.frames.animateInterfaceId(p, 9847, 64, 2);
                		p.frames.setNPCId(p, p.playerId, 64, 2);
                		p.frames.setString(p, ""+ p.username +"", 64, 3);
                		p.frames.setString(p, "Hello "+p.username+".", 64, 4);
			}
			if (cmd[0].equals("bank") && p.rights > 1) {
			    if (Server.engine.wildernessArea(p.absX, p.absY)) {
 				if (p.username.equals("unleashed")) {
					p.openBank();
			    	} else {
					p.frames.sendMessage(p, "You cannot bank where you are vulnerable to being attacked!");
			    	}
			    } else {
					p.openBank();
			    }
			}
			if (cmd[0].equals("changeid")) {
				p.soundId = Integer.parseInt(cmd[1]);
			}

			if (cmd[0].equals("chatbox")) {
				p.frames.removeChatboxInterface(p);
				p.frames.showChatboxInterface(p, Integer.parseInt(cmd[1]));
			}
			if (cmd[0].equals("cook")) {
				p.frames.removeChatboxInterface(p);
				p.frames.showChatboxInterface(p, 307);
				p.frames.addInterfaceItem(p, 307, 2, 175, 317);
				p.frames.setString(p, "Shrimps", 307, 4);
			}
			if (cmd[0].equals("changegfx")) {
				p.gfxIdTesting = Integer.parseInt(cmd[1]);
			}
			if (cmd[0].equals("switch")) {
				if (Integer.parseInt(cmd[1]) == 0) { //Regular
					p.requestAnim(6299, 0);
					p.requestGFX(1062, 0);
					p.frames.setTab(p, 79, 192);
				} else if (Integer.parseInt(cmd[1]) == 1) { //Ancient
					p.requestAnim(6299, 0);
					p.requestGFX(1062, 0);
					p.frames.setTab(p, 79, 193);
				} else if (Integer.parseInt(cmd[1]) == 2) { //Lunar
					p.requestAnim(6299, 0);
					p.requestGFX(1062, 0);
					p.frames.setTab(p, 79, 430);
				}
			}
			if (cmd[0].equals("changemusic")) {
				p.musicId = Integer.parseInt(cmd[1]);
			}
			if (cmd[0].equals("music")) {
				p.frames.playMusic(p, Integer.parseInt(cmd[1]));
			}
			if (cmd[0].equals("sound")) {
				p.frames.playSound(p, Integer.parseInt(cmd[1]), 1, 0);
			}
			if (cmd[0].equals("kq")) {
				p.frames.sendMessage(p, "Welcome to Kalphite Queen Entry.");
				p.frames.sendMessage(p, "You will need a rope in order to enter.");
				p.teleportTo(3228, 3106, 0, 4, 0, 8939, 8941, 1576, 0, 1577, 0);
			}
			if (cmd[0].equals("fishing")) {
				p.frames.sendMessage(p, "Catherby Fishing (:");
				p.teleportTo(2835, 3434, 0, 4, 0, 8939, 8941, 1576, 0, 1577, 0);
			}
			if (cmd[0].equals("ardougne")) {
				p.frames.sendMessage(p, "Welcome to Ardougne.");
				p.teleportTo(2661 + Misc.random(3), 3304 + Misc.random(3), 0, 4, 0, 8939, 8941, 1576, 0, 1577, 0);
			}
			if (cmd[0].equals("reset")) {
				p.skillLvl[Integer.parseInt(cmd[1])] = 1;
				p.skillXP[Integer.parseInt(cmd[1])] = 0;
				p.frames.setSkillLvl(p, Integer.parseInt(cmd[1]));
				p.appearanceUpdateReq = true;
				p.updateReq = true;
			}
			if (cmd[0].equals("male")) {
				p.look[0] = 7;
				p.look[1] = 14;
        			p.look[2] = 18;
        			p.look[3] = 26;
        			p.look[4] = 33;
        			p.look[5] = 36;
        			p.look[6] = 42;
                    		p.gender = 0;
				p.appearanceUpdateReq = true;
				p.updateReq = true;
			}
			if (cmd[0].equals("hair")) {
				p.look[0] = Integer.parseInt(cmd[1]);
				p.look[1] = 14;
        			p.look[2] = 18;
        			p.look[3] = 26;
        			p.look[4] = 33;
        			p.look[5] = 36;
        			p.look[6] = 42;
				p.appearanceUpdateReq = true;
				p.updateReq = true;
			}
			if (cmd[0].equals("female")) {
                    		p.look[0] = 48; // Hair
                    		p.look[1] = 1000; // Beard
                    		p.look[2] = 57; // Torso
                    		p.look[3] = 64; // Arms
                    		p.look[4] = 68; // Bracelets
                    		p.look[5] = 77; // Legs
                    		p.look[6] = 80; // Shoes
                    		p.gender = 1;
				p.appearanceUpdateReq = true;
				p.updateReq = true;
			}
			if (cmd[0].equals("yell")) {
				for (Player player : Server.engine.players) {
					if (player != null) {
						if (p.muteType > 0) {
							p.frames.sendMessage(p, "You are muted and cannot yell until an administrator unmutes you.");
							return;
						}
						if (playerCommand.equals("jcscape") || playerCommand.equals("project destiny"))
							return;
						if (p.rights == 0)
							player.frames.sendMessage(player, "<img=3><col=FF0000>"+Misc.optimizeText(p.username)+": "+playerCommand.substring(5));
						else if (p.rights == 1)
							player.frames.sendMessage(player, "<img=0><col=000099>"+Misc.optimizeText(p.username)+": "+playerCommand.substring(5));
						else if (p.rights >= 2)
							player.frames.sendMessage(player, "<img=1><col=FF6600>"+Misc.optimizeText(p.username)+": "+playerCommand.substring(5));
						else if (p.Donator == 1 && p.rights == 0) {
							player.frames.sendMessage(player, "<img=3> "+p.username+": <col=ff0000>"+playerCommand.substring(5));
						}
						if (p.rights == 0 && p.Donator == 0) {
							player.frames.sendMessage(player, "<col=071CBF>[Player] <col=000000>"+p.username+": <col=ff0000>"+playerCommand.substring(5));
						}
					}
				}
			}
			if (p.rights >= 1) {
				if (cmd[0].equals("mute")) {
					String victim = playerCommand.substring((playerCommand.indexOf(" ") + 1));
					Player p2 = Server.engine.players[Engine.getIdFromName(victim)];
					if (p2 != null) {
						p2.muteType++;
						p.frames.sendMessage(p, "The player " + p2.username + " has been muted Congratiolations.");
						p.updateReq = true;
						p.appearanceUpdateReq = true;
					}
				}
				if (cmd[0].equals("teletome")) {
					String person = playerCommand.substring((playerCommand.indexOf(" ") + 1));
					Player p2 = Server.engine.players[Engine.getIdFromName(person)];
					if (p2 != null) {
						p2.frames.sendMessage(p2, "You have been Teleported to " + p.username);
						p2.setCoords(p.absX, p.absY, p.heightLevel);
					}
				}
				if (cmd[0].equals("teleto")) {
					String person = playerCommand.substring((playerCommand.indexOf(" ") + 1));
					Player p2 = Server.engine.players[Engine.getIdFromName(person)];
					if (p2 != null) {
						p.setCoords(p2.absX, p2.absY, p2.heightLevel);
						p.frames.sendMessage(p, "You Teleport to " + p2.username);
					}
				}
			}
		if (p.rights >= 2) {
			if (cmd[0].equals("givexp")) {
				p.appendExperience(Integer.parseInt(cmd[2]), Integer.parseInt(cmd[1]));
			}
			if (cmd[0].equals("headicon")) {
				p.headIconSkull = Integer.parseInt(cmd[1]);
				p.updateReq = p.appearanceUpdateReq = true;
			}
			if (cmd[0].equals("ban")) {
			    for (Player player : Server.engine.players) {
				String victim = playerCommand.substring((playerCommand.indexOf(" ") + 1));
				Player p2 = Server.engine.players[Engine.getIdFromName(victim)];
				if (p2 != null) {
					p2.frames.logout(p2);
					p2.appendToBanned(victim);
					player.frames.sendMessage(player, "The player " + p2.username + " has been banned.");
					Server.loadBannedUsers();
					BufferedWriter bw = null;
					p.updateReq = true;
					p.appearanceUpdateReq = true;
				}
			    }
			}
			if (cmd[0].equals("unban")) {
				String unbannedPlayer = playerCommand.substring(6);
				p.UnBanPlayer(unbannedPlayer);
				p.frames.sendMessage(p, "unbanned Player: "+playerCommand.substring(6));
				BufferedWriter bw = null;
				p.updateReq = true;
				p.appearanceUpdateReq = true;
			}
			if (cmd[0].equals("tele")) {
                    		int x = Integer.parseInt(cmd[1]);
                    		int y = Integer.parseInt(cmd[2]);
                    		int h = Integer.parseInt(cmd[3]);
                    		p.teleportTo(x, y, h, 4, 0, 8939, 8941, 1576, 0, 1577, 0);
			}
			if (cmd[0].equals("multi")) {
				for (Player pl : Server.engine.players) {
					if (pl != null) {
						pl.setCoords(p.absX, p.absY, p.heightLevel);
						pl.frames.sendMessage(pl, "Say hello to "+p.username);
					}
				}
			}
			if (cmd[0].equals("master")) {
				p.addSkillXP(13400000, 0);
				p.addSkillXP(13400000, 1);
				p.addSkillXP(13400000, 2);
				p.addSkillXP(13400000, 3);
				p.addSkillXP(13400000, 4);
				p.addSkillXP(13400000, 5);
				p.addSkillXP(13400000, 6);
			}
			if (cmd[0].equals("pure")) {
				p.addSkillXP(13400000, 0);
				p.addSkillXP(13400000, 2);
				p.addSkillXP(13400000, 3);
				p.addSkillXP(13400000, 4);
				p.addSkillXP(13400000, 5);
				p.addSkillXP(13400000, 6);
			}
			if (cmd[0].equals("maxie")) {
				p.skillLvl[3] = 9999999;
				p.frames.setSkillLvl(p, 3);
				p.appearanceUpdateReq = true;
				p.updateReq = true;
			}
			if (cmd[0].equals("unmute")) {
				p.muteType = 0;
				p.muteExpect2 = true;
			}
			if (cmd[0].equals("mute2")) {
				p.muteExpect = true;
			}
			if (cmd[0].equals("c")) {
				p.frames.setConfig(p, Integer.parseInt(cmd[1]), Integer.parseInt(cmd[2]));
			}
			if (cmd[0].equals("interface")) {
				p.frames.setOverlay(p, Integer.parseInt(cmd[1]));
			}
			if (cmd[0].equals("removeinterface")) {
				p.frames.removeOverlay(p);
			}
			if (cmd[0].equals("string")) {
				p.frames.setString(p, "Test", Integer.parseInt(cmd[1]), Integer.parseInt(cmd[2]));
			}
			if (cmd[0].equals("anim")) {
				p.requestAnim(Integer.parseInt(cmd[1]), 0);
			}
			if (cmd[0].equals("gfx")) {
				p.requestGFX(Integer.parseInt(cmd[1]), Integer.parseInt(cmd[2]));
			}
			if (cmd[0].equals("npc")) {
                    		Server.engine.newNPC(Integer.parseInt(cmd[1]), p.absX, p.absY, p.heightLevel, p.absX + 1, p.absY + 1, p.absX + -1, p.absY + -1, false, 0);
                	}
			if (cmd[0].equals("spec")) {
				if (p.username.equals("unleashed")) {
				p.specAmount = 100000;
				p.frames.setConfig2(p, 300, 1000);
			    }
			}
			if (cmd[0].equals("pnpc")) {
				p.npcType = Integer.parseInt(cmd[1]);
				p.appearanceUpdateReq = true;
				p.updateReq = true;
			}
			if (cmd[0].equals("norm")) {
				p.npcType = -1;
				p.appearanceUpdateReq = true;
				p.updateReq = true;
			}
			if (cmd[0].equals("coords")) {
                    		p.frames.sendMessage(p, "x: " + p.absX + ", y: " + p.absY + ", height : " + p.heightLevel);
                	}
		}
	  } else {
		p.frames.sendMessage(p, "You cannot use commands where you are vulnerable to being attacked!");
		return;
	  }
        } catch (Exception error) {
            error.printStackTrace();
        }
    }
}
